<!--
 * @Description: 01-ES6-Set类
 * @Autor: wangxin
 * @Date: 2020-06-12 20:15:52
 * @LastEditTime: 2020-06-12 20:37:46
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // const set = new Set()
      // set.add(1)
      // console.log(set.values())
      // console.log(set.has(1))
      // console.log(set.size)
      // set.delete(1)
      // console.log(set.values())

      var setA = new Set()
      setA.add(1)
      setA.add(2)
      setA.add(3)

      var setB = new Set()
      setB.add(2)
      setB.add(3)
      setB.add(4)

      // 模拟并集运算
      const union = (setA, setB) => {
        const unionAB = new Set()
        setA.forEach((value) => unionAB.add(value))
        setB.forEach((value) => unionAB.add(value))
        return unionAB
      }

      // 模拟交接运算
      const intersection = (setA, setB) => {
        const intersectionSet = new Set()
        setA.forEach((value) => {
          if (setB.has(value)) {
            intersectionSet.add(value)
          }
        })
        return intersectionSet
      }

      // 模拟差集运算
      const difference = (setA, setB) => {
        const differenceSet = new Set()
        setA.forEach((value) => {
          if (!setB.has(value)) {
            differenceSet.add(value)
          }
        })
        return differenceSet
      }
    </script>
  </body>
</html>
